﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace DLL.TrainingExperience
{
	/// <summary>
	/// 培训经历数据类
	/// </summary>
	public class Database
	{
		//private string strConn = "";
		//private SqlConnection clsConn = new SqlConnection();
		private System.Web.UI.Page page = new System.Web.UI.Page();

		public Database(System.Web.UI.Page page)
		{
			this.page = page;

			//strConn = "server=172.16.8.163;database=apzx2014;uid=sa;pwd='sa123!'";

			//clsConn.ConnectionString = strConn;
		}

		public bool Add(Entity clsAddEntity)
		{
			string strSQL = "";

			strSQL = "INSERT INTO AP_pxjl (usysid, xm, pxsqrq, pxzzrq, pxdd, pxnr, pxts, pxzt, pxjg, pxlx, pxqd, ssdw, tj, jy) VALUES ('" + clsAddEntity.PersonID.ToString() + "', '" + clsAddEntity.PersonName + "', '" + clsAddEntity.StartDate + "', '" + clsAddEntity.EndDate + "', '" + clsAddEntity.Address + "', '" + clsAddEntity.Content + "', '" + clsAddEntity.DayNumber.ToString() + "', '" + clsAddEntity.State + "', '" + clsAddEntity.Organization + "', '" + clsAddEntity.Sort.ToString() + "', '" + clsAddEntity.Channel.ToString() + "', '" + clsAddEntity.PersonDepartmentID + "', '" + clsAddEntity.Count.ToString() + "', '" + clsAddEntity.Status.ToString() + "')";
			if (ExecuteSQL(strSQL) > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		private SqlConnection GetConnection()
		{
			SqlConnection lconn;

			lconn = new SqlConnection();
			try
			{
				lconn.ConnectionString = "server=172.16.8.163;database=apzx2014;uid=sa;pwd='sa123!'";
			}
			catch (Exception ex)
			{
				TonyNet4V1.ShowMessageAlert.ShowError(page, ex.Message);
				lconn = null;
			}
			finally
			{

			}

			return lconn;
		}

		public int ExecuteSQL(string strSQL)
		{
			SqlConnection conn = new SqlConnection();
			int n = 0;

			try
			{
				conn = GetConnection();
				conn.Open();

				SqlCommand cmd = new SqlCommand(strSQL, conn);
				n = cmd.ExecuteNonQuery();
			}
			catch (Exception ex)
			{
				TonyNet4V1.ShowMessageAlert.ShowError(page, ex.Message);
			}
			finally
			{
				if (conn != null)
				{
					conn.Dispose();
				}

			}
			return n;
		}
	}
}
